boolean类型
MYSQL保存BOOLEAN值时用1代表TRUE,0代表FALSE,boolean在MySQL里的类型为tinyint(1),
MySQL里有四个常量:true,false,TRUE,FALSE,它们分别代表1,0,1,0,
mysql> select true,false,TRUE,FALSE;
+------+-------+------+-------+
| TRUE | FALSE | TRUE | FALSE |
+------+-------+------+-------+
| 1 | 0 | 1 | 0 |
+------+-------+------+-------+
可以如下插入boolean值:insert into [xxxx(xx)] values(true),当然也可以values(1);
举例如下:
mysql> alter table test add isOk boolean;
Query OK
mysql> desc test;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| isOk | tinyint(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
mysql> insert into test(isOk) values(true);
Query OK
mysql> select isOk from test ;
+------+
| isOk |
+------+
| 1 |
+------+
=================
create table xs ( id int primary key, bl boolean ) |
因为惯性思维,在java类中也把它定义成type。然后在Struts中使用<s:check/>标签。这就产生一个严重的问题了。<s:check>是boolean,而POJO去定义成byte。这样数据永远也无法提交,被struts的intercept拦截掉了。解决办法是在POJO类中定义成boolean,在mysql中定义成tinyint(1)。